//
//  OnlineModel.m
//  XiXi
//
//  Created by HawkingWang on 16/10/9.
//  Copyright © 2016年 xi-xi.cc. All rights reserved.
//

#import "OnlineModel.h"

@implementation OnlineModel

-(OnlineModel *) initModel:(NSDictionary *)dic{
    if(self){
        self._id = dic[@"id"];
        self.name = dic[@"name"];
        if ([self.brief isKindOfClass:[NSNull class]]) {
            self.brief = @"";
        }else self.brief = dic[@"brief"];
        self.director = dic[@"director"];
        self.duration = dic[@"duration"];
        
        self.image = dic[@"image"];
        self.create_time = dic[@"create_time"];
        self.modify_time = dic[@"modify_time"];
        self.modifior = dic[@"modifior"];
        
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
        [dateFormatter setTimeZone:timeZone];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        [dateFormatter setDateFormat:@"yyyy.MM.dd"];
        
        NSTimeInterval startTimeInterval = [dic[@"online_time"] doubleValue];
        NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:startTimeInterval];
        NSString *startDateStr = [dateFormatter stringFromDate:startDate];
        self.online_time = startDateStr;
        
        NSTimeInterval endTimeInterval = [dic[@"offline_time"] doubleValue];
        NSDate *endDate = [NSDate dateWithTimeIntervalSince1970:endTimeInterval];
        NSString *endDateStr = [dateFormatter stringFromDate:endDate];
        self.offline_time = endDateStr;
        
        self.time = [NSString stringWithFormat:@"%@ ~ %@", self.online_time, self.offline_time];
        
        self.status = dic[@"status"];
        
        self.diff_time = dic[@"diff_time"];
        
        self.max_price = dic[@"max_price"];
        
        self.min_price = dic[@"min_price"];
        
        self.price = [NSString stringWithFormat:@"%d元 - %d元", [self.min_price intValue], [self.max_price intValue]];
    }
    return self;
}
+(OnlineModel *) initWithDic:(NSDictionary *)dic
{
    OnlineModel *model = [[OnlineModel alloc]init];
    return [model initModel:dic];
}


@end
